import {Component, OnInit, ViewChild} from '@angular/core'

@Component({
  selector: 'app-dom',
  templateUrl: './dom.component.html',
  styleUrls: ['./dom.component.scss']
})
export class DomComponent implements OnInit {
  //获取dom节点
  @ViewChild('mybox') mybox: any
  //获取组件
  @ViewChild('myheader') header: any


  constructor() {
  }

  ngOnInit(): void {
  }

  ngAfterViewInit(): void { //dom操作放在该生命周期函数
    let dom1 = document.getElementById('ok')
    console.log(dom1.innerHTML)
    // 通过ViewChild获取dom节点
    let dom2 = this.mybox.nativeElement
    console.log(dom2.innerHTML)

    this.header.run()
  }

}
